<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    class Stack {
      constructor() {
        this.stack = [];
      }

      push(value) {
        this.stack.push(value);
      }

      pop() {
        return this.stack.pop();
      }

      peek() {
        return this.stack[this.stack.length - 1];
      }

      isEmpty() {
        return this.stack.length === 0;
      }

      size() {
        return this.stack.length;
      }
    }

    let stack = new Stack();
    stack.push(1);
    stack.push(2);
    stack.push(3);
    console.log(stack.peek()); // 输出3
    console.log(stack.pop());  // 输出3
    console.log(stack.pop());  // 输出2

  </script>
</body>

</html>